#!/bin/bash

# 查看服务日志脚本

SERVICE_NAME=$1

if [ -z "$SERVICE_NAME" ]; then
    echo "========================================"
    echo "  Spring Cloud 服务日志查看"
    echo "========================================"
    echo ""
    echo "使用方法: ./logs.sh [服务名]"
    echo ""
    echo "可用服务："
    echo "  - mysql       MySQL 数据库"
    echo "  - nacos       Nacos 服务注册与配置中心"
    echo "  - sentinel    Sentinel 流量控制面板"
    echo "  - seata-server  Seata 分布式事务"
    echo "  - redis       Redis 缓存"
    echo "  - all         所有服务（不加参数）"
    echo ""
    echo "示例："
    echo "  ./logs.sh nacos       # 查看 Nacos 日志"
    echo "  ./logs.sh             # 查看所有服务日志"
    echo ""
    read -p "请输入要查看的服务名 (直接回车查看所有): " SERVICE_NAME
fi

if [ -z "$SERVICE_NAME" ]; then
    echo ""
    echo "📋 查看所有服务日志..."
    docker-compose logs -f
else
    echo ""
    echo "📋 查看 $SERVICE_NAME 服务日志..."
    docker-compose logs -f $SERVICE_NAME
fi

